#ifndef LIBSIMPLEX_LIBRARY
	#define LIBSIMPLEX_LIBRARY "bin/Simplex"
#endif

#define cart2i(x,y) ((x+y-1)*mapwidth)

/datum/simplex
	var/seed
	var/modify
	var/mapscale
	var/mapwidth
	var/mapheight
	var/min
	var/max
	var/map			//note the map is stored with x=0,y=0 at the top left (not the bottom left like byond coords)
	var/flatten

/datum/simplex/New(mapwidth, mapheight, mapscale=1, min, max, seedvalue, modify, flatten)
	src.mapwidth = mapwidth
	src.mapheight = mapheight
	src.mapscale = mapscale
	src.seed = seedvalue
	src.modify = modify
	src.flatten = flatten

	if(istext(min))
		min = text2ascii(min,1)
	src.min = min
	if(istext(max))
		max = text2ascii(max,1)
	src.max = max
	generate()

/datum/simplex/proc/generate(x,y)
	map = call(LIBSIMPLEX_LIBRARY, "generate_map")("[x]", "[y]", "[mapwidth]", "[mapheight]", "[mapscale]", ascii2text(min), ascii2text(max), "[seed]", modify, "[flatten]")
	return map

/datum/simplex/proc/read(x, y)
	return text2ascii(map, cart2i(x,y)) - min

#undef cart2i

#ifdef LIBSIMPLEX_LIBRARY
	#undef LIBSIMPLEX
#endif